package com.xiaoshuidi.cloud.module.member.controller.app.point;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.security.core.annotations.PreAuthenticated;
import com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils;
import com.xiaoshuidi.cloud.module.member.controller.app.point.vo.PointsForm;
import com.xiaoshuidi.cloud.module.member.controller.app.point.vo.TenantPointsRecordVo;
import com.xiaoshuidi.cloud.module.member.controller.app.point.vo.TenantPointsVo;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.point.MemberPointsRecordService;
import com.xiaoshuidi.cloud.module.member.service.point.MemberPointsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.xiaoshuidi.cloud.framework.web.core.util.WebFrameworkUtils.getLoginUserId;

/**
 * 
 * @description 租客相关接口
 * @author Morty.Wang
 * @date 2022年12月19日 下午8:27:32
 */
@Tag(name = "租客APP - 积分")
@Slf4j
@RestController
@RequestMapping(ApiConstants.NAME+"/points")
public class MemberPointController {
    @Autowired
    MemberPointsService tenantPointsService;
    @Autowired
    MemberPointsRecordService tenantPointsRecordService;

    /**
     * api 查询个人积分
     * 
     * @author neil
     * @date 2022-12-28 15:27:45 查询个人积分
     */
    @GetMapping("user/info")
    @Operation(summary = "查询个人积分")
    @PreAuthenticated
    public CommonResult<TenantPointsVo> points() {
        //获取租客id
        TenantPointsVo vo = tenantPointsService.getByTenantUserId(SecurityFrameworkUtils.getLoginUserId());
        return CommonResult.success(vo);
    }

    /**
     * api 查询个人信息
     *
     * @author neil
     * @date 2023-1-9 15:27:45 查询个人信息
     */
    @PostMapping("user/list")
    @Operation(summary = "查询个人信息")
    @PreAuthenticated
    public CommonResult<PageResult<TenantPointsRecordVo>> getUTenantPointsRecords(@RequestBody PointsForm form) {
        //获取租客id
        form.setTenantUserId(SecurityFrameworkUtils.getLoginUserId());
        PageResult<TenantPointsRecordVo> page = tenantPointsRecordService.getTenantPointsRecords(form);
        return CommonResult.success(page);
    }



}
